package RuMen_Demo;

import java.util.*;

public class 模拟双色球 {
    public static void main(String[] args) {
        // 一共7个球
        int[] s = new int[7];
        int[] s1 = new int[7];
        InPut(s);
        Result(s1);
        Judge(s, s1);
    }

    public static void InPut(int s[]) {
        int[] a = new int[100];
        Scanner sc = new Scanner(System.in);
        System.out.println("6个红球，范围：1～33－－－	－－－1个蓝球，范围：1～16\n注意规范输入！");
        for (int i = 0; i < 7; i++) {
            exit:
            while (true) {
                System.out.println("请输入你的第" + (i + 1) + "号双色球号码：");
                s[i] = sc.nextInt();
                if (i < 6 && (s[i] < 0 || s[i] > 33)) {
                    System.out.println("输入数字大小不规范！");
                    continue exit;
                }
                if (i == 6 && (s[i] < 0 || s[i] > 16)) {
                    System.out.println("输入数字大小不规范！");
                    continue exit;
                }
                if (a[s[i]] == 0) {
                    a[s[i]] = 1;
                    break;
                } else System.out.println("输入重复，请重新输入：");
            }
        }
        System.out.println("你的号码：");
        for (int i = 0; i < 7; i++) System.out.print(s[i] + " ");
        System.out.println("");
    }

    // 中奖的号码
    public static void Result(int s1[]) {
        int[] a = new int[100];
        Random r = new Random();
        int m = 0;
        for (int i = 0; i < 7; i++) {
            // 前6个为红球，后面一个为蓝球，范围：
            // 红球：1－33	蓝球：1－16
            while (true) {
                if (i != 6) m = r.nextInt(33) + 1;
                else m = r.nextInt(16) + 1;
                if (a[m] == 0) {
                    s1[i] = m;
                    a[m] = 1;
                    break;
                }
            }
        }
        System.out.println("中奖双色球号码：");
        for (int i = 0; i < 7; i++) System.out.print(s1[i] + " ");
        System.out.println("");
    }

    // 判断是否中奖
    public static void Judge(int s[], int s1[]) {
        for (int i = 0; i < 7; i++) {
            if (s[i] != s1[i]) {
                System.out.println("未中奖！\n谢谢惠顾！");
                return;
            }
        }
        System.out.println("恭喜你，中奖了！");
    }
}
